layui.use(['layer', 'form', 'admin', 'ax','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var upload = layui.upload;
    /**
     * 检索报销人
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyBxd/getBxr");
    var languageResult = languageAjax.start();
    $.each(languageResult, function( index, val ) {
        $("#btyBxdaId").append("<option value='"+val.id+"'>"+val.xm+"</option>");
    } );
    form.render('select');
    var ajax = new $ax(Feng.ctxPath + "/btyBxd/info?id=" + $("#id").val());
    var result = ajax.start();
    var roleFlag=result.roleFlag;
    if(roleFlag==1){
        $("#flag").attr("disabled","disabled");
    }
    if(result !=null){
        form.val('noticeForm', result);
        if(result.picture !=null && result.picture !=""){
            getPicture("layer-photos-demo",result.picture);
        }else{
            $("#layer-photos-demo").html("");
        }

    }

    var flag=result.flag;
    if(flag==1){
        $("#btyBxdaId").attr("disabled","disabled");
        $("#zcje").attr("readonly","readonly");
        $("#zy").attr("readonly","readonly");
        $("#bz").attr("readonly","readonly");
        //普通图片上传禁用
        $('#upload_btn').addClass("layui-btn-disabled").attr("disabled",true);
        form.render('select');
    }


    //图片回填
    function getPicture(id,picture){
        $("#"+id).html(
            "<div class='gs-upload-file-container'>"+
            "<div class='gs-upload-ele'>"+
            "<div class='progress-bar progress-bar-success progress-bar-striped gs-upload-progress-bar' style='width: 188px; display: none;'></div>" +
            "<div class='gs-upload-ele-img-div'>"+
            "<img class='gs-upload-ele-img' src='"+picture+"' style='cursor: pointer;width: 150px;height: 150px;' id='gs-upload-ele-img'>	"+
            "</div>	"+
            "<div class='gs-upload-ele-content'>"+
            "<div class='gs-upload-ele-title-div'></div>"+
            "<div class='gs-upload-ele-menu'>"+
            "</div></div></div></div>"
        );
    }
    layer.photos({
        photos: '#layer-photos-demo',
        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });

    layer.photos({
        photos: '#layer-photos-demo-back',
        anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
    });





    form.on('select(flag)', function(data){
        var flag=data.value;
        if(flag==1){
            $("#btyBxdaId").attr("disabled","disabled");
            $("#zcje").attr("readonly","readonly");
            $("#zy").attr("readonly","readonly");
            $("#bz").attr("readonly","readonly");
            form.render('select');
            //普通图片上传禁用
            $('#upload_btn').addClass("layui-btn-disabled").attr("disabled",true);
        }else if(flag==0){
            $('#btyBxdaId').removeAttr("disabled");
            $("#zcje").removeAttr("readonly");
            $("#zy").removeAttr("readonly");
            $("#bz").removeAttr("readonly");
            //普通图片上传
            $('#upload_btn').removeClass("layui-btn-disabled").attr("disabled",false);
        }
        form.render('select');

    });

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        $('#btyBxdaId').removeAttr("disabled");
        var ajax = new $ax(Feng.ctxPath + "/btyBxd/update", function (data) {
            Feng.success("修改成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();

        }, function (data) {
            Feng.error("修改失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
        //添加 return false 可成功跳转页面
        return false;
    });

});